<div class="form_item">
    <div class="form_item_block required">
        <%= scope[:form].fields_for(:pipeline, scope[:pipeline]) do |p_f| %>
            <%= required_label(p_f, com.thoughtworks.go.config.PipelineConfig::NAME, scope[:pipeline_name_label]) %>
            <%= p_f.text_field com.thoughtworks.go.config.PipelineConfig::NAME, :class => "required pattern_match uniquePipelineName" %>
            <%= error_message_on(scope[:pipeline], com.thoughtworks.go.config.PipelineConfig::NAME, :css_class => "form_error") %>
        <% end %>
    </div>
        <div class="form_item_block">
            <%= scope[:form].label com.thoughtworks.go.config.PipelineConfigs::GROUP, 'Pipeline Group Name' -%>
            <% if is_user_a_group_admin? %>
                <%= scope[:form].select com.thoughtworks.go.config.PipelineConfigs::GROUP, @groups_list, {:selected => @group_name}, {:id => 'pipeline_group_name_text_field'} %>
            <% else %>
                <%= scope[:form].text_field com.thoughtworks.go.config.PipelineConfigs::GROUP, :value => @group_name, :class => "required pattern_match", :id => 'pipeline_group_name_text_field' -%>
            <% end %>
            <%= error_message_on(scope[:pipeline_group], com.thoughtworks.go.config.PipelineConfigs::GROUP, :css_class => "form_error") %>
        </div>
</div>

<script type="text/javascript">
    var groups = <%== @groups_json %>
    jQuery("#pipeline_group_name_text_field").autocomplete(groups, {
        minChars: 0,
        width: 400,
        matchContains: "word",
        cacheLength: 0,
        formatItem: function(row, i, max) {
            return  row.group;
        },
        formatMatch: function(row, i, max) {
            return row.group;
        },
        formatResult: function(row) {
            return row.group;
        }
    });
</script>
